function queensAttacktheKing(queens: number[][], king: number[]): number[][] {
    // 从king 往八个方向找第一个
    let result: number[][] = []
    let arr: number[][] = []
    let length: number[] = []
    // const arr = [[0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]]
    queens.forEach(item => {
        console.log('皇后', item)
        const x = item[0] - king[0]
        const y = item[1] - king[1]
        if (x === 0 && y > 0) {
            console.log('皇后在方向右')
            if (arr[0]) {
                const len = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
                if (len < length[0]) {arr[0] = item; length[0] = len}
            } else {
                arr[0] = item
                length[0] = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
            }0
        } else if (x === 0 && y < 0) {
            console.log('皇后在方向左')
            if (arr[1]) {
                const len = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
                if (len < length[1]) {arr[1] = item; length[1] = len}
            } else {
                arr[1] = item
                length[1] = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
            }
        } else if (x > 0 && y === 0) {
            console.log('皇后在方向下')
            if (arr[2]) {
                const len = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
                if (len < length[2]) {arr[2] = item; length[2] = len; console.log('方向下更新', len, length[2], item)}
            } else {
                arr[2] = item
                length[2] = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
            }
        } else if (x < 0 && y === 0) {
            console.log('皇后在方向上')
            if (arr[3]) {
                const len = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
                if (len < length[3]) {arr[3] = item; length[3] = len}
            } else {
                arr[3] = item
                length[3] = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
            }
        } else if (x > 0 && x === y) {
            console.log('皇后在方向右下')
            if (arr[4]) {
                const len = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
                if (len < length[4]) {arr[4] = item; length[4] = len}
            } else {
                arr[4] = item
                length[4] = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
            }
        } else if (x < 0 && x === y) {
            console.log('皇后在方向左上')
            if (arr[5]) {
                const len = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
                if (len < length[5]) {arr[5] = item; length[5] = len}
            } else {
                arr[5] = item
                length[5] = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
            }
        } else if (x > 0 && x + y === 0) {
            console.log('皇后在方向左下')
            if (arr[6]) {
                const len = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
                if (len < length[6]) {arr[6] = item; length[6] = len}
            } else {
                arr[6] = item
                length[6] = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
            }
        } else if (x < 0 && x + y === 0) {
            console.log('皇后在方向右上')
            if (arr[7]) {
                const len = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
                if (len < length[7]) {arr[7] = item; length[7] = len}
            } else {
                arr[7] = item
                length[7] = Math.abs(item[0] - king[0]) + Math.abs(item[1] - king[1])
            }
            
        }
    })
    console.log('arr', arr)
    console.log('length', length)
    return arr.filter(item => item)
};


// const queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]
// const queens = [[1,3],[0,7],[5,1],[2,5],[7,2],[1,2],[6,7],[3,3],[5,5],[1,5],[5,0],[0,4],[4,1],[1,1],[3,2],[2,3],[4,2],[1,0],[6,5],[2,7],[3,1],[4,3],[3,4]], king = [0,2]
const queens = [[4,7],[5,6],[7,7],[0,7],[3,7],[2,5],[7,2],[4,0],[6,7],[7,6],[4,4],[6,3],[1,5],[2,2],[4,1],[1,1],[6,4],[5,4],[3,2],[2,6],[0,0],[7,5],[2,3],[0,5],[1,0],[3,5],[0,1],[2,7],[7,0],[4,6],[7,4],[0,6]], king = [2,4]

console.log (queensAttacktheKing(queens, king))